import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-04-01
 * Time: 23:06
 */
public class test1 {
    /**
     * 560
     */

    public int subarraySum(int[] nums, int k) {
        Map<Integer,Integer> map = new HashMap<>();
        // key是前缀和-k  value是出现的次数
        map.put(0,1);
        // 统计次数
        int ret = 0;
        int sum = 0;
        // 统计和
        for(int num:nums){
            sum += num;
            ret += map.getOrDefault(sum-k,0);
            map.put(sum,map.getOrDefault(sum,0)+1);
        }
        return ret;
    }
}
